package com.cocotingo.snail.template.models;

import com.cocotingo.snail.template.TemplateSyntaxException;

public abstract class VariableNode<T> extends IDNode {
	
	public static final int INTEGER = 0;
	public static final int DOUBLE = 1;
	
	public abstract int getType();
	public abstract T getDefaultValue();
	
	@Override
	public Iterable<Node> children() {
		return Node.EMPTY_ITERABLE;
	}

	public static class IntegerNode extends VariableNode<Integer> {
		
		private int defaultValue = 0;
		
		public Integer getDefaultValue() {
			return Integer.valueOf(defaultValue);
		}
		
		public void setDefaultValue(int defaultValue) {
			this.defaultValue = defaultValue;
		}

		@Override
		public int getType() {
			return INTEGER;
		}
		
		@Override
		public void validateNode() throws TemplateSyntaxException {
			super.validateNode();
		}

		@Override
		protected String getXMLNodeName() {
			return "Integer";
		}

		@Override
		protected String getXMLAttributes() {
			return String.format("id=\"%s\" default=\"%d\"", getID(), defaultValue);
		}
		
	}
	
	public static class DoubleNode extends VariableNode<Double> {
		
		private double defaultValue = 0.0;
		
		public Double getDefaultValue() {
			return Double.valueOf(defaultValue);
		}
		
		public void setDefaultValue(double defaultValue) {
			this.defaultValue = defaultValue;
		}

		@Override
		public int getType() {
			return DOUBLE;
		}
		
		@Override
		public void validateNode() throws TemplateSyntaxException {
			super.validateNode();
		}
		
		@Override
		protected String getXMLNodeName() {
			return "Double";
		}

		@Override
		protected String getXMLAttributes() {
			return String.format("id=\"%s\" default=\"%f\"", getID(), defaultValue);
		}
		
	}

}
